<template>
    <body class="hold-transition">
        <div id="app" style="width: 85vw;">
            <div class="content-header">
                <h1>系统设置<small>管理员管理</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>系统设置</el-breadcrumb-item>
                    <el-breadcrumb-item>管理员管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="管理员名称" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="normal" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="username" label="管理员姓名" align="center"></el-table-column>
                        <el-table-column label="管理员状态" align="center">
                            <template #default="scope">
                                <span>{{ scope.row.station == '0' ? '禁用' : '可用'}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="角色" align="center">
                            <template #default="scope">
                                <el-table size="small" current-row-key="id" :data="scope.row.roles" stripe highlight-current-row>
                                    <el-table-column type="index" align="center" label="序号"></el-table-column>
                                    <el-table-column prop="name" label="角色名称" align="center"></el-table-column>
                                    <el-table-column prop="keyword" label="角色关键字" align="center"></el-table-column>
                                </el-table>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center">
                            <template #default="scope">
                                <el-button type="primary" size="mini" @click="handleQuery(scope.row)">详情</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="findPage"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            :total="pagination.total"
                            :pager-count="11"
                            layout="total, prev, pager, next, jumper">
                        </el-pagination>
                    </div>
                    
                </div>
            </div>
        </div>
    </body>
</template>
  
<style scoped>
@import '../css/style.css';
</style>

<script>
import { useRouter } from 'vue-router';
import { ref, reactive , onMounted , toRefs } from 'vue';
import { ElMessage , ElMessageBox } from 'element-plus'
import service from '@/util/http';

export default {
    setup(props) {

        let data = reactive({
            pagination: {       //分页相关模型数据
                currentPage: 1, //当前页码
                pageSize:2,     //每页显示的记录数
                total:0,        //总记录数
                queryString:''  //查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            roles:[]//当前页要展示的角色列表数据
        });

        onMounted(() => {
            findPage();
        });

        //分页查询
        function findPage(page=1) {  
            //page=1 若未传递当前页码，默认查询第一页 ； 若传递当前页码，则设置当前页码
            data.pagination.currentPage = page
            let param = {
                currentPage:data.pagination.currentPage ,
                pageSize:data.pagination.pageSize,
                queryString:data.pagination.queryString
            }
            service.get('/admin/user/findPage' , { params:param })
                .then(response=>{
                    if(response.data.flag){
                        data.pagination.total = response.data.data.total;
                        data.dataList = response.data.data.records;
                        for (const i in data.dataList) {
                            data.roles = data.dataList[i].roles
                            console.log(data.roles)
                        }
                    }else{
                        ElMessage.error(response.data.message)
                        // router.push({path:'/'})
                    }
                }).catch(error=>{
                    console.log(error)
                })
        };

        //添加
        function handleCreate() {
            
        };

        //详情
        function handleQuery(row) {
            
        };
        
        // 删除
        function handleDelete(row) {
            
        };
        
        return {
            ...toRefs(data),
            findPage,
            handleCreate,
            handleQuery,
            handleDelete
        }

    }
}
</script>
  
  